<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">点击</button>
  </body>
  <script>


    // 节流
    var key = false;
    document.getElementById("btn").onclick = function () {
      if (!key) {
        key = true;
        console.log(111);
        // 请求，请求完成后，再次变为fasle,
        setTimeout(function () {
          key = false;
        }, 1000);
      }
    };
        /*   // 防抖：设置延时器，短时间高频率触发只有最后一次触发成功
    var timer;
    document.getElementById("btn").onclick = function () {
      clearTimeout(timer);
      timer = setTimeout(function () {

        console.log(1111)
      },1000);
    }; */
  </script>
  
</html>
